<?php

	$pageTitle="Детайли за продукта | Artist Design T-shirts";
	include "includes/header.php";
    include "includes/common.php";

    //BASIC SECURITY CHECKS
    if (!isset($_GET['item'])) Header('Location:index.php');
    $selectedItem = (int)htmlspecialchars($_GET['item']);
    if($selectedItem > (count($pics_men)-1) && $selectedItem < 300 ||
        $selectedItem > (count($pics_women)+299) || !is_numeric($selectedItem)) $selectedItem = 0;

    //CHECK MALE OR FEMALE ITEM
    if((int)$selectedItem > 299) {
        $pageResult = array_rand($pics_women, 4);
        $arrayHolder = $pics_women;
    } else {
        $pageResult = array_rand($pics_men, 4);
        $arrayHolder = $pics_men;
    }

    //CREATE VARS FOR SIZE CHECKS
    $nalichni_razmeri = explode(",", $arrayHolder[$selectedItem]['sizes']);
    $check_S = filter_var($nalichni_razmeri[0], FILTER_SANITIZE_NUMBER_INT);
    $check_M = filter_var($nalichni_razmeri[1], FILTER_SANITIZE_NUMBER_INT);
    $check_L = filter_var($nalichni_razmeri[2], FILTER_SANITIZE_NUMBER_INT);

    //FB LIKE ADDRESS
    if(defined('HTTP_HOST') && defined('REQUEST_URI')) {
        $like_address = 'http://'.$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI];
    } else {
        $like_address = 'http://www.artistdesign.eu/';
    }

//FORM NORMALIZATION AND VALIDATION - ime, familiq, email, tel, strana, grad, pkod, adres1, adres2
    $error = "";

    if($_POST) {
        $ime = trim(strip_tags($_POST['ime']));
        $familiq = trim(strip_tags($_POST['familiq']));
        $email = trim(strip_tags($_POST['email']));
        $tel = trim(strip_tags($_POST['tel']));
        $strana = trim(strip_tags($_POST['strana']));
        $grad = trim(strip_tags($_POST['grad']));
        $pkod = (int)strip_tags($_POST['pkod']);
        $adres1 = trim(strip_tags($_POST['adres1']));
        $adres2 = trim(strip_tags($_POST['adres2']));


        if(count($ime) < 3 ) $error = 'Моля въведете коректно име';
        if(count($familiq) < 2 ) $error = 'Моля въведете коректно фамилно име';
        if(count($email) < 4 || strpos($email, '@') == false) $error = 'Моля въведете валиден имейл адрес';
        if(count($tel) < 7 ) $error = 'Моля въведете коректен телефонен номер (вкл. префикси за населени места)';
        if(count($strana) < 3 ) $error = 'Моля въведете коректна държава';
        if(count($grad) < 3 ) $error = 'Моля въведете коректен град';
        if(count($pkod) < 2 ) $error = 'Моля въведете коректен пощенски код';

    }
?>

    <!--FACEBOOK ROOT LIKE DIV AND SCRIPT-->
    <div id="fb-root"></div>
    <script>(function(d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) return;
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));
    </script>


		<!--sales-->
		
		<br/>
		
		
		<div id="container_buypage">
		<div id="container_buypage_billboard">

		<!-- ZOOMING BUY PICTURE -->
		<span class="zoom" id="image1">		    
		    <img src="<?php echo $arrayHolder[$selectedItem]['loc_big']?>" id="img_01" alt="buypic" height="425" width="246">
		    <img class="zoomImg" src="<?php echo $arrayHolder[$selectedItem]['loc_big']?>">

            <?php


            ?>


		</span> 
		    
		    <div id="info_product">
		    <h2><?php echo $arrayHolder[$selectedItem]['bg_name']?></h2>
		    <p><?php echo $arrayHolder[$selectedItem]['descr']?></p>
		    
		    <div id="razmeri">
		    	<h4>Налични Размери:</h4>
	     		<?php if (isset($check_S) && $check_S > 0) : ?>
                    <span class="razmer" id="S"><img src="img/small_white.png"></span>
                <?php endif; ?>
                <?php if (isset($check_M) && $check_M > 0) : ?>
                    <span class="razmer" id="M"><img src="img/medium_white.png"></span>
                <?php endif; ?>
                <?php if (isset($check_L) && $check_L > 0) : ?>
                    <span class="razmer" id="L"><img src="img/large_white.png"></span>
                <?php endif; ?>
            </div>
                <div class="fb-like" data-href=""
                     data-width="The pixel width of the plugin" data-height="The pixel height of the plugin"
                     data-colorscheme="light" data-layout="standard" data-action="like" data-show-faces="true"
                     data-send="false">
                </div>
            <div id="product_prices">
            <span id="price"> Цена:</span> <span id="old_price_product"> 45 лв.</span><br/>
            <span id="new_price_product"> <?php echo $arrayHolder[$selectedItem]['price'];?>лв.</span>
           
            </div>
            
             <input type="image" id="btn_buy" src="img/btn_buy.png">
		     </div>

		
		</div>
		<div id="payment_info">
		
		<div id="receiving">
	    <h2>Начин на плащане</h2><br/>
	    <form method="POST" action="">
            <label for="ekont_ofis">Офис на Спиди: 5.50 лева</label>
            <input type="radio" name="ekont" id="ekont_ofis" value="ekont_ofis" checked="checked"><br/>
            <label for="ekont_adres">На адрес: 5.50 лева</label>
            <input type="radio" name="ekont" id="ekont_adres" value="ekont_adres">

	    
	    </div>	
		
		<div id="payment">
            <br/><h2>Изберете начин на плащане</h2><br/>

	    <input type="radio" name="payment" value="payment" checked="checked">В брой при доставката (наложен платеж) 

		    
		</div>
		
		<div id="select_office">
		<select name="Адрес на Еконт">
		<optgroup label="България">
            <?php
                foreach($result as $value) {
                    echo '<option>'.$value.'</option>';
                }
            ?>
		</optgroup>
        
		</select>
		</div>
		</div>
		
		</div>
		
		
		
		
		<div id="person_info">
		    
		    <h2>Попълнете вашите данни за доставка и контакт</h2>
		    <?php echo $error; ?>

		    <div class="infos">
		    <div><input type="text" name="ime" class="text_field" value="" placeholder="Име*"></div>
            <div><input type="text" name="familiq" class="text_field" value="" placeholder="Фамилия*"></div>
            <div><input type="text" name="email" class="text_field" value="" placeholder="Емайл адрес*"></div>
            <div><input type="text" name="tel" class="text_field" value="" placeholder="Мобилен Телефон*"></div>
            
            <!--[if lt IE 10]>
            <script src="js/placeholder.js"></script>
        <![endif]-->
		    </div>
		    
		    
		    <div class="infos">
		    <div><input type="text" name="strana" class="text_field" value="" placeholder="България*"></div>
            <div><input type="text" name="grad" class="text_field" value="" placeholder="Град/Село*"></div>
            <div><input type="text" name="pkod" class="text_field" value="" placeholder="Пощ. Код*"></div>
            <div><input type="text" name="adres1" class="text_field" value="" placeholder="Адрес за доставка*"></div>
            <div><input type="text" name="adres2" class="text_field" value="" placeholder="Адресна линия 2*"></div>

            <!--[if lt IE 10]>
            <script src="js/Placeholder.js"></script>
        <![endif]-->
           
		    
		    </div>
		    
		    <textarea rows="7" cols="30" placeholder="Задайте Въпрос..."></textarea>
		    <!--[if lt IE 10]>
            <script src="js/Placeholder.js"></script>
        <![endif]-->
		    <form>
		    <input id="buy_it" type="submit" value="Купи">
            </form>
		</div>
		
		<div id="other_models">
		    
		    <h2>Други Модели</h2>

            <?php

                if (isset($pageResult) && $pageResult > 0) {
                    # Обхождане на резултатите
                    foreach ($arrayHolder as $key => $value) {
                        foreach($pageResult as $value1) {
                            if ((int)$key != (int)$value1) {
                                continue;}
                            echo '<div class="other_models_holders">
                            <img src="'.$value['loc_small'].'">
                            <h3>'.$value['bg_name'].'</h3>
                            <div class="prices"><span class="old_price">45</span><span class="new_price">30лв.</span></div>
                            <div class="sad"><a href="buypage.php?item='.$key.'"> Детайли </a></div>
                            </div>';
                        }
                    }
                } else echo("Няма добавени снимки");
            ?>

		    
		</div>
		   
		   
<?php include "includes/footer.php";?>